package com.ljy.cameralibrary.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Rect;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;
import androidx.core.view.GestureDetectorCompat;

import com.ljy.cameralibrary.R;
import com.ljy.cameralibrary.utils.DensityUtils;

import java.util.logging.Logger;


/**
 * OpenGL录制视频控件
 *
 * @author CainHuang
 * @date 2019/7/7
 */
public class GLRecordView extends GLSurfaceView {
    private boolean showZheZhao = false;

    private Bitmap bitmap = null;


    public GLRecordView(Context context) {
        super(context);
        init();
    }

    public GLRecordView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
    }


    private Rect mSrcRect, mDestRect;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
        int height = this.getHeight();
        if (showZheZhao) {
            mSrcRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
            //            Logger.d("width  :" + getWidth() + "height  :" + getHeight());
            mDestRect = new Rect(getWidth() / 2 - bitmap.getWidth() / 2, getHeight() / 2 - bitmap.getHeight() / 2,
                    getWidth() / 2 + bitmap.getWidth() / 2, getHeight() / 2 + bitmap.getHeight() / 2);
            canvas.drawColor(Color.parseColor("#80FF5776"));
            canvas.drawBitmap(bitmap, mSrcRect, mDestRect, null);
        }


    }

    public void setZheZhao(boolean flag, Bitmap bitmap) {
        this.showZheZhao = flag;
        this.bitmap = bitmap;
    }


}
